<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String mainid = request.getParameter("mainid");
%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@ include file="../jslib/jquerylib.jsp" %>
		 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jqGrid/css/jqgrid.css"></link>
	  <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
	  <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
      <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
     <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
     <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css">
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
	<style>
		.ui-jqgrid .ui-jqgrid-htable th div,.ui-jqgrid tr.ui-row-ltr td,.ui-jqgrid .ui-jqgrid-title ,.ui-paging-info,.ui-pg-table {font-size:12px;}
		.ui-jqgrid .ui-pg-input{height:18px;}
	</style>
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var stateValue="";
    var epids="${epids}";
    var editGrid=0;
    $(document).ready(function(){
    	var lastrow=0;
    	var lastcell=0;
			var option1s = {
		    	   url:'<%=request.getContextPath() %>/equipmentParts!shenheEPInStore.action?steptype='+$("#steptype0").val()+'&taskinfoid='+${taskinfoid},
		    	    beforeSubmit: function() {
		    	    	var flag = checkForm();
		  	    	 	if(flag){
							return $('#pageFrom').validate().form();
		  	    	 	}
		   				return flag;
		    			
		    		},
		    	    dataType:'json',
		    	    success: function(data) {
		    	      if(data.result=='success'){
		    	        buttonDisabled();
						alert("提交成功");
						flowtaskid = data.taskid;
						changeButtonDisabled();
						api.close();
					    W.reload();
						
		    	      }else{
		    	      	alert("系统繁忙，请您稍后再试！");
		    	      	api.close();
						W.reload();
		    	      }
		    	}};
			$("#gridTable").jqGrid({
				url:'<%=request.getContextPath() %>/equipmentParts!queryEPDataListByids.action?epInstoreno='+'${epInstoreno}',
				datatype: "json",
				height: 130,
				width: 820,
				colNames:['序号','设备序号','仓库名称（部门）','备件代码','备件名称','备件属性','备件等级','规格型号','品牌','供应商','单价(元)',
							'采购周期','最大库存','最小库存','实际库存','入库数量','入库金额','实际入库数量','计量单位','适用设备','适用设备编号','存放地点'],
				colModel:[
                        {name:'id',index:'id', key:true,hidden:true,hidedlg:true,editable:true,edittype:'text'}, 
						{name:'epid',index:'epid', hidden:true,editable:true,edittype:'text'}, 
						{name:'epStorehouse',index:'epStorehouse', width:100},
						{name:'epCode',index:'epCode', width:120},	
						{name:'epName',index:'epName', width:100},								
						{name:'epProperty',index:'epProperty', width:100,hidden:true},
						{name:'epLevel',index:'epLevel', hidden:true},
						{name:'epGuige',index:'epGuige', hidden:true},
						{name:'epBrand',index:'epBrand',hidden:true},
						{name:'epSupplier',index:'epSupplier', width:105},
						{name:'epInstoreprice',index:'epInstoreprice', width:55},
						{name:'epIncycle',index:'epIncycle', width:100,hidden:true},
						{name:'epMaxstock',index:'epMaxstock', width:60},
						{name:'epMinstock',index:'epMinstock', width:60,hidden:true},
						{name:'epActualstock',index:'epActualstock', width:60},
						{name:'epInstorenum',index:'epInstorenum', width:60},
						{name:'epInstoremoney',index:'epInstoremoney',hidden:true},
						{name:'epInactualnum',index:'epInactualnum', width:80,editable:true,edittype:'text',editrules:{number:true}},
						{name:'epMeasurementunit',index:'epMeasurementunit', width:100,hidden:true},
						{name:'epApplicableequipment',index:'epApplicableequipment', width:100,hidden:true},
						{name:'epApplicableequipmentid',index:'epApplicableequipmentid', width:100,hidden:true},	
						{name:'epStoragelocation',index:'epStoragelocation', width:100,hidden:true}	,

			],
			shrinkToFit:false,  
			//autoScroll: false,
			ondblClickRow:function(rowid,iRow, iCol,e) {
					var id=rowid;
					$.dialog({
				        title: '备件详细信息查看',
				        content: 'url:'+ '<%=request.getContextPath() %>/equipmentParts!queryEPInstoreViewById.action?id='+id,
				        okVal: false,//确定按钮文字
				        cancelVal: false,//取消按钮文字
				        min: true, //是否显示最小化按钮
				        max: false,//是否显示最大化按钮
				        fixed: false,//开启静止定位
				        lock: true,//开启锁屏
				        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
				        time: null,//设置对话框显示时间
				        resize: false,//是否允许用户调节尺寸
				        drag: true,//是否允许用户拖动位置
				        cache: false,//是否缓存iframe方式加载的窗口内容页
				        width: '900px',
				        closeOnEscape:true,
				        zIndex: 4086, 
				        height: 630
					});
			},			
			sortname:'epCode',
			sortorder:'desc',
			viewrecords:true,
			multiselect: false, // 是否显示复选框
			multiboxonly : true, 
			//gridview: true,  //提升速度
			rownumbers: true,//显示行号
			rownumWidth: 30, //行号的宽度
			rowNum:15,
			rowList:[15,20,50,400,510],
			toolbar: [false,"top"],
			hidegrid: false,
			cellsubmit: 'remote',
			cellEdit:true,
			cellurl:'<%=request.getContextPath() %>/equipmentParts!updateEPInstoreInfo.action',
			jsonReader: {
				root:"rows",		// 数据行（默认为：rows）
				page: "page",  	// 当前页
				total: "total",  // 总页数
				records: "records",  // 总记录数
				repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
			},
			prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
			pager:"#gridPager",
			caption: "备件列表",
			beforeEditCell:function(rowid,cellname,v,iRow,iCol)
			{	
			lastrow = iRow;	lastcell = iCol;editGrid=editGrid+1;
			}

			
	});
	    $("#consoleDlg").dialog({
	        autoOpen: false,      
	        modal: true,    // 设置对话框为模态（modal）对话框  
	        resizable: true,      
	        width: 700,  
	        buttons: {  // 为对话框添加按钮  
	            "关闭": function() {$("#consoleDlg").dialog("close")}
	        }  
	    }); 
		 jQuery("#gridTable").jqGrid('navGrid','#gridPager',{add:false,edit:false,del:false,search:false,refresh:false});
		//	jQuery("#gridTable").jqGrid('navButtonAdd','#gridPager',
		//				{ 	
		//				caption: "",                          
		//				onClickButton : function (){                               
		//				jQuery("#gridTable").jqGrid('setColumns');                           
		//				}
		//	}); 
						doResize(); 
					//	afterCompleteFunction();										
 

		$('#saveBtn').click(function(){
			    	$('#pageFrom').ajaxSubmit(options);
	 	            return false;
    	 });
		$('#savesaveBtn').click(function(){
			 var msg = "请仔细确认入库数量，您确定要提交吗？"; 
			  if (confirm(msg)==true){ 
				  if(editGrid>0){
				      $("#gridTable").jqGrid("saveCell",lastrow,lastcell);
				  }
			    $('#pageFrom').ajaxSubmit(option1s);
			    return false;
			  }else{ 
			    return false; 
			  } 
			
        });
    	$('#closeBtn').click(function(){
    		api.close();
			//window.close();
		});
		
	});
	//grid失去焦点事件
	
  //执行大小
  
	function doResize() { 
		var ss = getPageSize(); 
		//alert(ss.WinH);
		
		//	 $("#gridTable").jqGrid('setGridHeight', ss.WinH-475);
		//	 $("#gridTable").jqGrid('setGridWidth', ss.WinW-60); 
			} 
    function buttonDisabled(){				
		for (i = 0;i < document.all.length; i++)
		{
			if (document.all[i].type == 'button' || document.all[i].type == 'submit' || document.all[i].type == 'reset')
			{
				document.all[i].disabled = true;
			}
		}			
	}
    function changeButtonDisabled(){	
		for (i = 0;i < document.all.length; i++)
		{
			if (document.all[i].type == 'button' || document.all[i].type == 'submit' || document.all[i].type == 'reset'){
				document.all[i].disabled = false;
			}
		}	
    } 
    function getrealLength(values){
	       var realLength = 0, len =values.length, charCode = -1;
		   for (var i = 0; i < len; i++) {
		        charCode = values.charCodeAt(i);
		        if (charCode >= 0 && charCode <= 128){
		          realLength += 1;
		        }
		        else {
		         realLength += 2;
		        }
		   }
		   return realLength;
	   }
    function checkForm()
    {
       var flag ='0';
       $("textarea").each(function(){
	      if(flag=='0'){
	         var cnName = $(this).attr("cnname");
		     var len =$(this).attr("leg");
		     var realLength = getrealLength(this.value);
		     if(realLength>parseInt(len)){
		        if(cnName!=''&&len!=''){
		           alert(cnName+"最多为"+len+"个字符,字符输入超出限制!");
		           flag='1';
		        }
		        this.value = cutString1(this.value,parseInt(len));
		        $(this).focus();
		     }
	      }
	   });
	   if(flag=='1'){
	       return false;
	   }
	 //  if($("#pageFrom").form('validate') == true){
	//		return $('#pageFrom').validate().form();
	 //  }else{
	//		return $("#pageFrom").form('validate');
	 //  }
     }
   	function checking(){
   		var flag = true;
		var epInshr = $("#epInshr").val();
	
		if(epInshr ==null || epInshr == "" ){
			alert("审核人不能为空！");
			$("#epInshr").focus();
    		return false;
		}
		
		
	}
	 
	function checkExp(inputData){ 
		var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
		var result = inputData.match(regEx);
		if (result == null) {
			return false;
		}
		return true;
	}
	function checkNum(inputData){
		var sNumber;
	    sNumber=Number(inputData);
	    if (isNaN(inputData)){
	       return false;
	     }
	    return true;
	}
	 function validateNum(){  
	      var reg = new RegExp("^[0-9]*$");  
	      var obj = document.getElementById("name");  
	   if(!reg.test(obj.value)){  
	       alert("请输入数字!");  
	  }  
		   if(!/^[0-9]*$/.test(obj.value)){  
		       alert("请输入数字!");  
		     }  
	 }
		 	
	function countlen1(textarea){
	       var elem = event.relatedTarget || event.srcElement || event.target ||event.currentTarget;    
	        if(event.keyCode!=8)
			{
			  if (textarea.value.length> 249){
			        alert("最多为250个字符,字符输入超出限制!");
			        textarea.value=textarea.value.substring(0,249);
			    }
			    return true;
	 	    }
	}
		
	  //选择部门
	function selectdept(id)
	{
		var datas = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/choose_organizationIndex.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=550px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById("dept_"+id).value = json1.ORG_NAME;
			 document.getElementById(id).value = json1.ORG_ID;
		}
	}
	
	//选择人员
	function selectperson(id)
	{
		 var users = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/chooseAllUser.jsp", window, "dialogWidth:900px;status:no;dialogHeight:500px");
    	if (users != null) {
    		var userIds = [];
            var userNames = [];
            for(var i=0;i<users.length;i++){
                userIds.push(users[i]['userid']);
                userNames.push(users[i]['username']);
            }
			    $("#"+id).val(userNames.join());
		        $("#"+id+"ID").val(userIds.join());
		   }
	}
	//alert(${flowid});
	function addSampleGrid(){
	}

   </script>
 	<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{font-size: 12px;border: 1px solid #999;padding: 5px;width: 760px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
  </head>
  
  <body>
 
<form id="pageFrom" action="" enctype="multipart/form-data" method="post">
        <input type="hidden" id="flag" name="flag" />
        <input type="hidden" name="flowid" id="flowid" value="${flowid}">
     	<input type="hidden" name="stateid" id="stateid" value="${stateid}">
     	${steptcontent}
     	<input type="hidden" name="id" id="id" value="${epis.id}">
  				
  	<table width='100%' border='0' align='center' class='formTableNew'>
  <tr> 
   <td style='text-align:right;width:120px;'>流程名称：</td>
   <td colspan='3'>
       <input type='hidden' id='flowname' name='flowname' value="${flowname}"  style='border: 1px solid #999;padding: 5px;width:705px'>
       <input type='text' disabled="disabled" id='flowname1' name='flowname1' value="${flowname}"  style='border: 1px solid #999;padding: 5px;width:705px'>
    </td>
    </tr>
  <tr>
   <td align="right">入库单号：</td>
   <td align="left">
      <input  style="border: 1px solid #999;padding: 5px;width: 250px;" type="hidden" id="epInstoreno" name="epInstoreno" value="${epInstoreno}" readOnly />
      <input disabled="disabled" style="border: 1px solid #999;padding: 5px;width: 250px;" type="text" id="epInstoreno1" name="epInstoreno1" value="${epInstoreno}" readOnly class='easyui-validatebox'  required missingMessage='必填' />
     </td>
     <td align="right">入库日期：</td>
     <td align="left">
      <input  type="hidden" id="epInstoredate"  name="epInstoredate" value="${epInstoredate}"  />
     <input disabled="disabled" readonly=readonly  style="border: 1px solid #999;padding: 5px;width: 250px;" type="text" id="epInstoredate1" onClick="WdatePicker()" name="epInstoredate1" value="${epInstoredate}"  />
     </td>
     </tr>
     <tr>
     <td align="right">入库类型：</td><td align="left">
      <input id="epInstoretype" type="hidden"  name="epInstoretype" value="${epInstoretype}" / >
     <select id="epInstoretype1" disabled="disabled" class='fselect' name="epInstoretype1" value="${epInstoretype}"  >
     <option value="采购">采购</option>
     <option value="随机">随机</option>
     <option value="借用归还">借用归还</option>
     <option value="回收">回收</option>
     <option value="自制">自制</option>
     <option value="其他">其他</option>
     </select></td>
     <td align="right">申请部门：</td>
     <td align="left">
     <input type="text" disabled="disabled" style="border: 1px solid #999;padding: 5px;width: 250px;"  readonly=readonly id="dept_epInsqdep" name="dept_epInsqdep" value="${epInsqdepname}"/>
  	</td>
     </tr>
     <tr>
     
     <td align="right">申请人：</td>
     <td align="left">
     <input type="text" disabled="disabled" class='finput'   readonly=readonly id="epInsqr" name="epInsqr"  value="${epInsqrname}" /></td>
     </tr>
	 <!--  <tr>
  			  <td align="right">选择仓管员：</td>
  			  <td align="left">
  			  	 <input type="hidden" id="epInshrID" name="epInshrID" value="${epis.epInshr }"/>
  			  	 <input  type="text"  id="epInshr" name="epInshr" maxlength="50"  style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;" />
  			     <img src="<%=request.getContextPath() %>/images/xh.png"  align="absmiddle"></img>
  			    <img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectperson('epInshr')" />
  			  </td>
  			</tr> -->
  		   <tr>
  		     <td colspan='4' align='center'>
  		     <div id='tt1' class='easyui-tabs' style='overflow:visible;width:850px;height:270px'>
  		      <div title='入库备件信息表' style='padding:10px;width:840px'>
  		      
                <table id="gridTable"></table>
                <div id="gridPager">
                </div>
              </div>
			</div>	
			</td>
				<!--	<td colspan="4" style="padding-top:8px;">
						<table id="gridTable"></table>
						<div id="gridPager"></div>
					</td>
					  -->
				</tr>
	  <tr>
	     <td align="right">审核人：</td>
         <td align="left">
       <input type="hidden" id="epInshr" name="epInshr" value="${userid}"/>
      <input disabled="disabled" style="border: 1px solid #999;padding: 5px;width: 250px;" type="text" id="epInshr1" name="epInshr1" value="${username}" readOnly class='easyui-validatebox'  required missingMessage='必填' />
     </td>
     <td align="right">审核日期：</td>
     <td align="left">
     <input  type="hidden" id="epInshrq" onClick="WdatePicker()" name="epInshrq" value="${epInshrq}"  />	
     <input disabled="disabled" style="border: 1px solid #999;padding: 5px;width: 250px;" type="text" id="epInshrq1" onClick="WdatePicker()" name="epInshrq1" value="${epInshrq}"  />	
	 </tr>
	 <tr>
	  <td align="right">审核意见：</td>
         <td colspan="3" align="left">
         <textarea  rows="3" cols="3" class='ftextarea' id="epRemark" name="epRemark" ></textarea>
     </td>
	 </tr>
		</table>

		<table width="100%" border="0" align="center" class="formTableNew">
		  <tr>
			<td align="center">
		<!--<input id="saveBtn" type="button" value="提 交" class="form_bt_orange" />-->
			<input id='savesaveBtn' type='button'  value='提交' class='form_bt_orange' />   	
		    <input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		    </td>
		  </tr>
		  
		</table>
	<!--表单结束-->
	</form>
  </body>
</html>